package com.xbongbong.saas.script.tempenum;

import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.SubFormPoJo;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.business.StockStandingBookEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 台账
 *
 * @author lee
 * @version v1.0
 * @date 2019/1/19
 * @since v1.0
 */
@Getter
public enum TempStockStandingBookEnum {
    // 显示模板字段
    CATEGORY_ID(StockStandingBookEnum.CATEGORY_ID),
    SERIALNO(StockStandingBookEnum.SERIALNO),
    NAME(StockStandingBookEnum.NAME),
    SPECIFICATION(StockStandingBookEnum.SPECIFICATION),
    UNIT(StockStandingBookEnum.UNIT),
    WAREHOUSE_ID(StockStandingBookEnum.WAREHOUSE_ID),
    ORI_STOCK(StockStandingBookEnum.ORI_STOCK),
    PERIOD_INSTOCK(StockStandingBookEnum.PERIOD_INSTOCK),
    PERIOD_OUTSTOCK(StockStandingBookEnum.PERIOD_OUTSTOCK),
    REMAINING_STOCK(StockStandingBookEnum.REMAINING_STOCK),

    ;

    private StockStandingBookEnum anEnum;

    TempStockStandingBookEnum(StockStandingBookEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempStockStandingBookEnum> getAllEnum() {
        List<TempStockStandingBookEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initOriStock(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity num = InitExplainsHelper.setField("num_1", "数量", "type", FieldTypeEnum.NUM.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        num.setParentAttr(ORI_STOCK.getAnEnum().getAttr());
        items.add(num);
        FieldAttrEntity cost = InitExplainsHelper.setField("num_2", "成本", "phone", FieldTypeEnum.NUM.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        cost.setParentAttr(ORI_STOCK.getAnEnum().getAttr());
        items.add(cost);
        FieldAttrEntity totalCost = InitExplainsHelper.setField("num_3", "成本合计", "phone", FieldTypeEnum.NUM.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        totalCost.setParentAttr(ORI_STOCK.getAnEnum().getAttr());
        items.add(totalCost);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.CUSTOM.getAlias());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
    }

    public static void initRemainingStock(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity num = InitExplainsHelper.setField("num_1", "数量", "type", FieldTypeEnum.NUM.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        num.setParentAttr(REMAINING_STOCK.getAnEnum().getAttr());
        items.add(num);
        FieldAttrEntity cost = InitExplainsHelper.setField("num_2", "成本", "phone", FieldTypeEnum.NUM.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        cost.setParentAttr(REMAINING_STOCK.getAnEnum().getAttr());
        items.add(cost);
        FieldAttrEntity totalCost = InitExplainsHelper.setField("num_3", "成本合计", "phone", FieldTypeEnum.NUM.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        totalCost.setParentAttr(REMAINING_STOCK.getAnEnum().getAttr());
        items.add(totalCost);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.CUSTOM.getAlias());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
    }

    public static void initPeriodInstock(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity num = InitExplainsHelper.setField("num_1", "数量", "type", FieldTypeEnum.NUM.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        num.setParentAttr(PERIOD_INSTOCK.getAnEnum().getAttr());
        items.add(num);
        FieldAttrEntity totalCost = InitExplainsHelper.setField("num_2", "成本合计", "phone", FieldTypeEnum.NUM.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        totalCost.setParentAttr(PERIOD_INSTOCK.getAnEnum().getAttr());
        items.add(totalCost);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.CUSTOM.getAlias());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
    }

    public static void initPeriodOutstock(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity num = InitExplainsHelper.setField("num_1", "数量", "type", FieldTypeEnum.NUM.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        num.setParentAttr(PERIOD_OUTSTOCK.getAnEnum().getAttr());
        items.add(num);
        FieldAttrEntity totalCost = InitExplainsHelper.setField("num_2", "成本合计", "phone", FieldTypeEnum.NUM.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        totalCost.setParentAttr(PERIOD_OUTSTOCK.getAnEnum().getAttr());
        items.add(totalCost);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.CUSTOM.getAlias());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
    }

}
